package com.bocaizp.operation.controller.user;

import com.bocaizp.common.result.Result;
import com.bocaizp.operation.service.HomeService;
import com.bocaizp.pojo.DTO.PositionFatherDTO;
import com.bocaizp.pojo.VO.HomeGoodJobVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Author : huang jie
 * Date : 2024/5/6 22:29
 **/
@RestController
@RequestMapping("/user")
@Slf4j
@CrossOrigin
public class HomeController {

	@Autowired
	private HomeService homeService;
	@Autowired
	private RedisTemplate redisTemplate;

	/**
	 * 主页职位信息
	 * @return
	 */
	@PostMapping("/position")
	public Result<List<PositionFatherDTO>> getPosition(){
		log.info("主页职位信息请求...");
		List<PositionFatherDTO> fatherDTOS = homeService.getPosition();
		return Result.success(fatherDTOS);
	}

	/**
	 * 精选职位
	 * @return
	 */
	@PostMapping("/good/job")
	public Result<List<HomeGoodJobVo>> goodJob(){
		log.info("精选职位请求...");
		List<HomeGoodJobVo> homeGoodJobVoList = (List<HomeGoodJobVo>) redisTemplate.opsForValue().get("hotJob");
		if(homeGoodJobVoList != null && !homeGoodJobVoList.isEmpty()){
			log.info("使用redis缓存数据...");
			return Result.success(homeGoodJobVoList);
		}
		List<HomeGoodJobVo> homeGoodJobVos = homeService.getGoodJob();
		redisTemplate.opsForValue().set("hotJob",homeGoodJobVos);
		return Result.success(homeGoodJobVos);
	}
}
